import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    //404
    path: '/404',
    component: () => import('@/views/404/index.vue'),
    name: '404',
    meta: {
      title: '404',
      isShow: true,
      icon: 'DocumentDelete',
      layout: false,
    },
  },
  {
    //任意路由
    path: '/:pathMatch(.*)*',
    redirect: '/404',
    name: 'Any',
    meta: {
      title: '任意路由',
      isShow: false,
      icon: 'DataLine',
      layout: false,
    },
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue'),
    meta: { title: '登录', icon: 'User',isShow:false,layout:false },
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/Register.vue'),
    meta: { title: '注册', icon: 'User',isShow:false,layout:false },
  },
  {
    path: '/',
    component: () => import('@/components/layout/BasicLayout.vue'),
    name: 'BasicLayout',
    redirect: '/dashboard',
    meta: {
      title: import.meta.env.VITE_APP_TITLE,
      icon: 'HomeFilled',
      isShow:true,
      layout:true
  },
  children: [
    {
      path: '/dashboard',
      name: 'Dashboard',
      component: () => import('@/views/HomeView.vue'),
      meta: { title: '首页', icon: 'HomeFilled',isShow:true,layout:true }
    },
    {
      path: '/userinfo', 
      name: 'UserInfo',
      component: () => import('@/views/users/Userinfo.vue'),
      meta: { title: '个人信息', icon: 'User',isShow:false,layout:true },
    },
    {
      path: '/user',
      name: 'User',
      component: () => import('@/components/layout/BasicLayout.vue'),
      meta: { title: '用户管理', icon: 'UserFilled',isShow:true,layout:true },
      redirect: '/user/users',
      children: [
        {
          path: 'users', // 注意路径格式
          name: 'Users',
          component: () => import('@/views/users/Users.vue'),
          meta: { title: '用户信息',isShow:true,layout:true }
        }
      ]
    },
    {
      path: '/restaurant',
      name: 'Restaurant',
      component: () => import('@/components/layout/BasicLayout.vue'),
      redirect: '/restaurant/restaurants',
      meta: { title: '餐厅管理', icon: 'Setting',isShow:true,layout:true },
      children: [
        {
          path: 'restaurants',
          name: 'Restaurants',
          component: () => import('@/views/restaurant/Restaurant.vue'),
          meta: { title: '餐厅信息',isShow:true,layout:true }
        },
        {
          path: 'dishCategory',
          name: 'DishCategory',
          component: () => import('@/views/restaurant/DishCategory.vue'),
          meta: { title: '菜品分类',isShow:true,layout:true }
        },
        {
          path: 'dish',
          name: 'Dish',
          component: () => import('@/views/restaurant/Dish.vue'),
          meta: { title: '菜品信息',isShow:true,layout:true }
        }
      ]
    },
    {
      path: '/order',
      name: 'Order',
      component: () => import('@/components/layout/BasicLayout.vue'),
      meta: { title: '订单管理', icon: 'UserFilled',isShow:true,layout:true },
      redirect: '/order/orders',
      children: [
        {
          path: 'orders', // 注意路径格式
          name: 'Orders',
          component: () => import('@/views/order/Orders.vue'),
          meta: { title: '订单信息',isShow:true,layout:true }
        }
      ]
    },
  ]
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
    //滚动行为
    scrollBehavior() {
      return {
          left: 0,
          top: 0,
      }
  },
})

export default router